package org.example.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration;

/**
 * 初始化
 */
public class SpringMVCAppInitializer extends
        AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        //指定对应的service/dao/datasource的配置文件
        return new Class[]{RootWebContext.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        //对应的是 webMVC configuration
        return new Class[]{WebMVCContext.class};
    }

    @Override
    protected String[] getServletMappings() {
        // 指定dispatcher servlet能够映射到的请求url
        return new String[]{"/"};
    }

    @Override
    protected Filter[] getServletFilters() {
        return new Filter[]{
                new CharacterEncodingFilter("UTF-8")};
    }

    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        registration.setMultipartConfig(
                new MultipartConfigElement("/WEB-INF/upload",
                        1024 * 1024 * 10,
                        1024 * 1024 * 10,
                        1024 * 1024 * 10));
    }
}
